package jessiey.jdbc.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class ConnectionPool {
	/**
	 * load Driver and CreateConnection
	 * 
	 * @return Connection
	 * @throws SQLException
	 * 
	 *             private static ConnectionPool connection = null; private
	 *             ConnectionPool() {
	 *             dataSource.setDriverClassName(PropertyConnection
	 *             .newDBHelper() .getDRIVER_CLASS());
	 *             dataSource.setUrl(PropertyConnection.newDBHelper().getURL());
	 *             dataSource
	 *             .setUsername(PropertyConnection.newDBHelper().getUSERNAME());
	 * 
	 *             dataSource.setMaxActive(5); dataSource.setMaxIdle(3);
	 *             dataSource.setMaxWait(10); }
	 * 
	 *             public static ConnectionPool createConnection() { if
	 *             (connection == null) { connection = new ConnectionPool(); }
	 *             return connection; } /** public Connection getConn() { try {
	 *             con = dataSource.getConnection(); } catch (SQLException e) {
	 * 
	 *             e.printStackTrace(); } return con;
	 * 
	 *             }
	 **/
	public static Connection getConnection() {
		Connection connection = null;
		try {
			Context con = new InitialContext();
			DataSource data = (DataSource) con
					.lookup("java:comp/env/jdbc/myjdbc");
			connection = data.getConnection();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return connection;
	}

}
